;
INCLUDE				PIOC_INC.ASM
;
;
					ORG   0X0000
					DW    0X0000
					JMP   MCU_START
					DW    0X0FFF
;
UART_TX_FREQ		EQU   SFR_DATA_REG0
UART_TX_CNT			EQU   SFR_DATA_REG1
UART_TX_HALF_CNT	EQU   SFR_DATA_REG2
UART_TX_CTRL		EQU   SFR_DATA_REG3
UART_RX_FREQ		EQU   SFR_DATA_REG4
UART_RX_CNT			EQU   SFR_DATA_REG5
UART_RX_CTLR		EQU   SFR_DATA_REG6
UART_TX_RX_FLAG		EQU   SFR_DATA_REG7
;
VAR_SIZE_L			EQU   SFR_DATA_REG24
VAR_SIZE_H			EQU   SFR_DATA_REG25
UART_TX_CHECK		EQU   SFR_DATA_REG26
UART_TX_I		    EQU   SFR_DATA_REG27
UART_RX_CHECK		EQU   SFR_DATA_REG28
UART_RX_VAR			EQU   SFR_DATA_REG29
UART_RX_SR			EQU   SFR_DATA_REG30
UART_RX_DATA		EQU   SFR_DATA_REG31
;
DELAY_5NOP:         NOP
					RET
;
;
UART_TX:			MOVL  0X00
					MOVA  SFR_TMR0_INIT
					MOV   UART_TX_FREQ,A
					MOVA  SFR_TIMER_CTRL
TX_NEXT:			BC    SFR_PORT_IO,SB_PORT_OUT1
					CLR   SFR_TMR0_COUNT
					MOV   SFR_INDIR_PORT2,A
					MOVA  SFR_DATA_EXCH
					BTSS  UART_TX_CTRL,3
					BC    UART_TX_CHECK,0
TX_START:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_START
					BTSC  UART_TX_CTRL,3
					BS    UART_TX_CHECK,0
					NOP
					BP2F  BO_PORT_OUT1,0
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
TX_BIT0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT0
					NOP
					NOP
					NOP
					BP2F  BO_PORT_OUT1,1
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
TX_BIT1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT1
					NOP
					NOP
					NOP
					BP2F  BO_PORT_OUT1,2
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
TX_BIT2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT2
					NOP
					NOP
					NOP
					BP2F  BO_PORT_OUT1,3
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
TX_BIT3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT3
					NOP
					NOP
					NOP
					BP2F  BO_PORT_OUT1,4
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
					NOP
					BTSC  UART_TX_RX_FLAG,5
					JMP   TX_BIT_LEN
					NOP
TX_BIT4:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT4
					NOP
					NOP
					NOP
					BP2F  BO_PORT_OUT1,5
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
					NOP
					BTSC  UART_TX_RX_FLAG,6
					JMP   TX_BIT_LEN
					NOP
TX_BIT5:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT5
					NOP
					NOP
					NOP
					BP2F  BO_PORT_OUT1,6
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
					NOP
					BTSC  UART_TX_RX_FLAG,7
					JMP   TX_BIT_LEN
					NOP
TX_BIT6:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT6
					NOP
					NOP
					NOP
					BP2F  BO_PORT_OUT1,7
					CLR   SFR_TMR0_COUNT
					MOV   UART_TX_CHECK,A
					BCTC  BI_PORT_IN1
					RCL   UART_TX_CHECK
					XOR   UART_TX_CHECK
TX_BIT_LEN:			DEC   VAR_SIZE_L
					INC   VAR_SIZE_L,A
					BTSC  SFR_STATUS_REG,SB_FLAG_Z
					DEC   VAR_SIZE_H
					NOP
					NOP
					NOP
					MOV   UART_TX_CHECK,A
					BTSS  UART_TX_RX_FLAG,4
					JMP   TX_CHECK_0
					CLRA
					BTSC  UART_TX_CTRL,3
					ADDL  0X01
					NOP
					NOP
TX_CHECK_0:			MOVA  SFR_DATA_EXCH
TX_BIT7:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_BIT7
					BTSS  UART_TX_CTRL,2
					JMP	  TX_CHECK_NONE
					NOP
					BP2F  BO_PORT_OUT1,0
					CLR   SFR_TMR0_COUNT
TX_CHECK:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_CHECK
					NOP
					NOP
					NOP
TX_CHECK_NONE:		BS    SFR_PORT_IO,SB_PORT_OUT1
					CLR   SFR_TMR0_COUNT
					MOV   VAR_SIZE_L,A
					IOR   VAR_SIZE_H,A
					JZ    TX_STOP_FINAL
					DEC   UART_TX_I
					JNZ   TX_NOR_REQ
					BTSC  UART_TX_RX_FLAG,1
					MOVIA SFR_DATA_REG8
					MOVL  0X02
					XOR   UART_TX_RX_FLAG
					MOVL  0X08
					MOVA  UART_TX_I
					BS    SFR_SYS_CFG,SB_INT_REQ
					NOP
					NOP
TX_NOR_REQ:			NOP
					NOP
TX_STOP:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_STOP
					BTSS  UART_TX_CTRL,0
					JMP   TX_NEXT
					MOV   UART_TX_HALF_CNT,A
					MOVA  SFR_TMR0_COUNT
TX_STOP1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_STOP1
					BTSS  UART_TX_CTRL,4
					JMP   TX_STOP1_1
					JMP   TX_STOP1_1
TX_STOP1_1:			BTSS  UART_TX_CTRL,5
					JMP   TX_STOP1_2
					NOP
					JMP   TX_STOP1_2
TX_STOP1_2:			BTSS  UART_TX_CTRL,1
					JMP   TX_NEXT
					MOV   UART_TX_HALF_CNT,A
					MOVA  SFR_TMR0_COUNT
TX_STOP2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_STOP2
					BTSS  UART_TX_CTRL,6
					JMP   TX_STOP2_1
					JMP   TX_STOP2_1
TX_STOP2_1:			BTSS  UART_TX_CTRL,7
					JMP   TX_STOP2_2
					NOP
					JMP   TX_STOP2_2
TX_STOP2_2:			NOP
					JMP   TX_NEXT
;
TX_STOP_FINAL:		MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_STOP_FINAL
					BTSS  UART_TX_CTRL,0
					JMP   UART_RX
					MOV   UART_TX_HALF_CNT,A
					MOVA  SFR_TMR0_COUNT
TX_STOP_FINAL1:		MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_STOP_FINAL1
					BTSS  UART_TX_CTRL,4
					JMP   TX_STOP_FINAL1_1
					JMP   TX_STOP_FINAL1_1
TX_STOP_FINAL1_1:	BTSS  UART_TX_CTRL,5
					JMP   TX_STOP_FINAL1_2
					NOP
					JMP   TX_STOP_FINAL1_2
TX_STOP_FINAL1_2:	BTSS  UART_TX_CTRL,1
					JMP   UART_RX
					MOV   UART_TX_HALF_CNT,A
					MOVA  SFR_TMR0_COUNT
TX_STOP_FINAL2:		MOV   SFR_TMR0_COUNT,A
					ADD   UART_TX_CNT,A
					JNC   TX_STOP_FINAL2
					BTSS  UART_TX_CTRL,6
					JMP   TX_STOP_FINAL2_1
					JMP   TX_STOP_FINAL2_1
TX_STOP_FINAL2_1:	BTSS  UART_TX_CTRL,7
					JMP   TX_STOP_FINAL2_2
					NOP
					JMP   TX_STOP_FINAL2_2
TX_STOP_FINAL2_2:	NOP
					JMP   UART_RX
;
UART_RX:			BC   UART_TX_RX_FLAG,0
					MOVL  0X00
					MOVA  SFR_TMR0_INIT
					MOV   UART_RX_FREQ,A
					MOVA  SFR_TIMER_CTRL
RX_WAIT:			WAITB WB_PORT_XOR0_0
					WAITB WB_PORT_XOR0_1
					CLR   SFR_TMR0_COUNT
					CLR   UART_RX_CHECK
					CLR   SFR_DATA_EXCH
					CLR   UART_RX_VAR
					NOP
RX_START_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_START_0
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_START_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_START_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_START_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_START_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					JMP   RX_WAIT
					NOP
					NOP
RX_START_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_START_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT0_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT0_0
					NOP
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT0_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT0_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT0_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT0_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,0
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT0_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT0_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT1_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT1_0
					NOP
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT1_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT1_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT1_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT1_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,1
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT1_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT1_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT2_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT2_0
					NOP
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT2_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT2_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT2_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT2_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,2
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT2_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT2_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT3_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT3_0
					NOP
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT3_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT3_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT3_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT3_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,3
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT3_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT3_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT4_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT4_0
					NOP
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT4_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT4_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT4_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT4_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,4
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT4_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT4_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT5_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT5_0
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_TX_RX_FLAG,5
					JMP   RX_CHECK
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT5_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT5_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT5_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT5_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,5
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT5_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT5_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT6_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT6_0
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_TX_RX_FLAG,6
					JMP   RX_CHECK
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT6_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT6_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT6_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT6_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,6
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT6_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT6_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_BIT7_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT7_0
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_TX_RX_FLAG,7
					JMP   RX_CHECK
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT7_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT7_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					NOP
					NOP
					NOP
					NOP
RX_BIT7_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT7_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					BS    SFR_DATA_EXCH,7
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
RX_BIT7_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_BIT7_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_CHECK_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_CHECK_0
					NOP
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
RX_CHECK:			CLR   SFR_TMR0_COUNT
					BTSS  UART_RX_CTLR,1
					JMP   RX_STOP
					NOP
					NOP
RX_CHECK_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_CHECK_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_TX_RX_FLAG,4
					CLR   UART_RX_CHECK
					NOP
					NOP
RX_CHECK_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_CHECK_2
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,5
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,1
					INC   UART_RX_CHECK
					MOV   UART_RX_CTLR,A
					XOR   UART_RX_CHECK
RX_CHECK_3:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_CHECK_3
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_CTLR,4
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					CLR   UART_RX_VAR
					NOP
RX_STOP_0:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_STOP_0
					NOP
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_CHECK,0
					BS    UART_RX_SR,0
					NOP
RX_STOP:			NOP
RX_STOP_1:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_STOP_1
					BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSC  UART_RX_CTLR,6
					CALL  DELAY_5NOP
					CLR   SFR_TMR0_COUNT
					BTSC  UART_RX_CTLR,7
					JMP   RX_STOP_3
					NOP
					NOP
RX_STOP_2:			MOV   SFR_TMR0_COUNT,A
					ADD   UART_RX_CNT,A
					JNC   RX_STOP_2
RX_STOP_3:			BCTC  BI_PORT_IN0
					BTSC  SFR_STATUS_REG,SB_FLAG_C
					INC   UART_RX_VAR
					BTSS  UART_RX_VAR,1
					BS    UART_RX_SR,1
					MOV   UART_RX_VAR,A
					RCR   UART_RX_VAR
					XOR   UART_RX_VAR
					BTSC  UART_RX_VAR,0
					BS    UART_RX_SR,2
					MOV   SFR_DATA_EXCH,A
					MOVA  UART_RX_DATA
					BS    SFR_SYS_CFG,SB_INT_REQ
					JMP   RX_WAIT
;
;
MCU_START:			NOP
					NOP
					BS    SFR_PORT_IO,SB_PORT_OUT1
					BS    SFR_PORT_IO,SB_PORT_OUT0
					MOVA1F  0B00000010
					WAITB  WB_DATA_MW_SR_1
					MOVL  0X08
					MOVA  UART_TX_I
					CLR   UART_RX_SR
					MOVIA SFR_DATA_REG8
					BTSC  UART_TX_RX_FLAG,0
					JMP   UART_TX
					JMP   UART_RX
					JMP   MCU_START
;
END
;
